package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.dto.OrderDto;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.entity.Page;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: dw
 * @Date 2022/3/17 20:10
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired(required = false)
    private OrderService orderService;

    @RequestMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        orderService.addOrder(orders);
        return R.success("下单成功");
    }

    /**
     * 获取登录用户的订单分页数据
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/userPage")
    public R<Page<OrderDto>> userPage(Integer page, Integer pageSize){
        Page<OrderDto> orderDtoPage = orderService.findByPage(page, pageSize);
        return R.success(orderDtoPage);
    }
}
